home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 10 / 010.d81 / dos #27 < prev    next >
Text File  |  2022-08-26  |  4KB  |  204 lines

  1.  
  2.       DOS and don'ts -- Part 27
  3.            by Jimmy Weiler
  4.  
  5.  
  6.  
  7.   Now we'll discuss some special
  8.  
  9. techniques. Up to now in our
  10.  
  11. discussion of RELative files we have
  12.  
  13. assumed that you would want to read an
  14.  
  15. entire record, start to finish,
  16.  
  17. whenever you accessed the file. It is
  18.  
  19. possible that you would only want to
  20.  
  21. read one of many fields inside any
  22.  
  23. particular record.
  24.  
  25.   This wouldn't gain you much in a
  26.  
  27. file with only two fields per record,
  28.  
  29. but if you stored first name, last
  30.  
  31. name, phone number, street address,
  32.  
  33. city, state, zip code, social security
  34.  
  35. number, weight, hair color, driver's
  36.  
  37. license number, and shoe size in each
  38.  
  39. record, it could mean a 95% time
  40.  
  41. savings every time you checked
  42.  
  43. somebody's shoe size.
  44.  
  45.   Here's how:
  46.  
  47. Decide in advance how big each field
  48.  
  49. is allowed to be -- remember to allow
  50.  
  51. space for the carriage returns.  Then
  52.  
  53. add up the fields' lengths to find out
  54.  
  55. where in each record to write that
  56.  
  57. information.  A RELative file accessed
  58.  
  59. normally, with one INPUT# after
  60.  
  61. another is like a bunch of little
  62.  
  63. SEQ files.  A RELative file accessed
  64.  
  65. this way is like a bunch of little
  66.  
  67. REL files.
  68.  
  69. Field name         Length     Position
  70. --------------------------------------
  71.  First name       =  12              1
  72.  Last name        =  12             13
  73.  Phone number     =  17             25
  74.  Street address   =  28             44
  75.  City             =  18             72
  76.  State            =   3             90
  77.  Zip code         =   6             93
  78.  S/S/N            =  10             99
  79.  weight           =   4            109
  80.  Hair color       =   8            114
  81.  Driver's lic.    =  12            122
  82.  Shoe size        =   7            134
  83.  -------------------------------------
  84.                   TOTAL            141
  85.  
  86.  
  87.  A single record would look like this:
  88.  
  89. --------------------------------------
  90. <first name><last name ><-phone number
  91. ---><----street address--------><city-
  92. ----------->st.<zip ><ssn----->wgt.<--
  93. hair><-driver's-><shoe->
  94. --------------------------------------
  95.  
  96.  
  97. And typical data might be:
  98.  
  99. --------------------------------------
  100. Jimmy/      Weiler/     (318)868-7247/
  101.     4025 Greenway Rd./          Shreve
  102. port/       LA/71130/123500292/180/bla
  103. ck/  6069023/    10 1/2/
  104. --------------------------------------
  105.  
  106.   Every time you wanted to read from
  107.  
  108. or write to the file, you would
  109.  
  110. precede your INPUT# or PRINT# with
  111.  
  112. a POSITION command to the appropriate
  113.  
  114. character in the record.
  115.  
  116.   Here's the code that you would need
  117.  
  118. to write an entire record:
  119.  
  120. 10 OPEN 15,8,15
  121. 20 OPEN 3,8,4,"INFOFILE,L,"+CHR$(141)
  122. 30 INPUT"Read what record?";R
  123. 40 HB=INT(R/256):LB=R-(HB*256)
  124. 50 P$="P"+CHR$(4)+CHR$(LB)+CHR$(HB)
  125. 60 PRINT#15,P$CHR$(1)
  126. 70 PRINT#3,FIRST$
  127. 80 PRINT#15,P$CHR$(13)
  128. 90 PRINT#3,LAST$
  129. 100 PRINT#15,P$CHR$(25)
  130. 110 PRINT#3,PHNE$
  131. 120 PRINT#15,P$CHR$(44)
  132. 130 PRINT#3,ADDRESS$
  133. 140 PRINT#15,P$CHR$(72)
  134. 150 PRINT#3,CITY$
  135. 160 PRINT#15,P$CHR$(90)
  136. 170 PRINT#3,S$
  137. 180 PRINT#15,P$CHR$(93)
  138. 190 PRINT#3,ZIP$
  139. 200 PRINT#15,P$CHR$(99)
  140. 210 PRINT#3,SSN$
  141. 220 PRINT#15,P$CHR$(109)
  142. 230 PRINT#3,WT$
  143. 240 PRINT#15,P$CHR$(114)
  144. 250 PRINT#3,HAIR$
  145. 260 PRINT#15,P$CHR$(122)
  146. 270 PRINT#3,DL$
  147. 280 PRINT#15,P$CHR$(134)
  148. 290 PRINT#3,SHOE$
  149.  
  150.  
  151.   That's quite a bit of work for your
  152.  
  153. Commodore to have to do, but it's
  154.  
  155. worth it.  Now, if you want someone's
  156.  
  157. shoe size you don't need:
  158.  
  159.  
  160. 295PRINT#15,"P"CHR$(3)CHR$(LB)CHR$(HB)
  161.    CHR$(1)
  162. 300 INPUT#3,X$,X$,X$,X$,X$,X$,X$,X$,
  163.     X$,X$,X$,SHOE$
  164.  
  165.  
  166.  (All those X$'S are throw-away
  167.   strings. They are just there to
  168.   accept INPUT from all the fields
  169.   that don't interest us.)
  170.  
  171.  
  172. All you need to do is position to the
  173.  
  174. byte of the Shoe Size field and do
  175.  
  176. a single INPUT#
  177.  
  178.  
  179. 310PRINT#15,"P"CHR$(3)CHR$(LB)CHR$(HB)
  180.    CHR$(134)
  181. 320INPUT#3,SHOE$
  182.  
  183.  
  184. That's a savings of 11 INPUT#'s.
  185.  
  186.  
  187.   Remember, INPUT from and OUTPUT to
  188.  
  189. the 1541 drive is slow, compared to
  190.  
  191. how fast your Commodore can handle
  192.  
  193. data.  Any technique that can get
  194.  
  195. pertinent data from the disk drive
  196.  
  197. with fewer INPUT#'s will make your
  198.  
  199. program appear to run faster, and
  200.  
  201. ultimately, frustrate the user less.
  202.  
  203. --------- <end of article> -----------
  204.